Option Strict Off
Option Explicit On
Namespace BMLERP
	Friend Class frmACR110
		Inherits System.Windows.Forms.Form
		Dim OldCTTYP As String
		Private Sub WriteToFile()
			Dim cmdExecute As Object
			Dim SQLInsert As String
			If ISADDING Then
				SQLInsert = " INSERT INTO RCT " & "(CTTYP,CTDSC) " & "VALUES " & "('" & txtCTTYP.Text & "', '" & txtCTDSC.Text & "')"
			Else
				SQLInsert = "UPDATE RCT SET CTTYP = '" & txtCTTYP.Text & "', CTDSC ='" & txtCTDSC.Text & "' " & " WHERE CTTYP ='" & OldCTTYP & "'"

			End If

			cmdExecute = New ADODB.Command
			cmdExecute.ActiveConnection = DBconn
			cmdExecute.CommandText = SQLInsert
			cmdExecute.Execute()

		End Sub

		Private Sub WriteToScreen()
			Dim TBL As ADODB.Recordset
			If ISADDING Then 'gan rong
				txtCTTYP.Text = ""
				txtCTDSC.Text = ""
				' txtUMCVF = 0
			Else
				TBL = New ADODB.Recordset
				TBL.Open("  Select RCT.* From RCT where  CTTYP ='" & cboCTTYP.BoundText & "'", DBconn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
				If TBL.EOF = False Then
					txtCTTYP.Text = IIf(IsDBNull(TBL.Fields("CTTYP").Value), "", TBL.Fields("CTTYP").Value)
					txtCTDSC.Text = IIf(IsDBNull(TBL.Fields("CTDSC").Value), "", TBL.Fields("CTDSC").Value)
					'   txtUMCVF = IIf(IsNull(TBL!UMCVF), "", TBL!UMCVF)
				Else
					cboCTTYP.BoundText = ""
					txtCTTYP.Text = ""
					txtCTDSC.Text = ""
					'   txtUMCVF = 0
				End If
				TBL.Close()
			End If
			OldCTTYP = txtCTTYP.Text
		End Sub

		Sub ButtonStatus()
			cmdAddnew.Enabled = Not ISEDITING
			cmdEdit.Enabled = Not ISEDITING
			cmdSave.Enabled = ISEDITING	' And txtIMITN <> ""
			cmdDelete.Enabled = Not ISEDITING 'And txtIMITN <> ""
			cmdCancel.Enabled = ISEDITING
			Frame1.Enabled = ISEDITING
			'txtIMITN.Locked = Not ISADDING ' Lock item code tru truong hop ISADDING=true
			'txtDepartment.Enabled = ISEDITING
			'cboDepartment.Visible = Not ISADDING
			'txtDepartmentID.Visible = ISADDING
		End Sub



		Private Sub cboCTTYP_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboCTTYP.ClickEvent
			If eventArgs.area = 2 Then
				WriteToScreen()
			End If


		End Sub

		Private Sub cmdAddnew_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAddnew.Click
			ISADDING = True
			ISEDITING = True
			WriteToScreen()

			' Ham Gan tri man hinh
			ButtonStatus()

		End Sub

		Private Sub cmdCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancel.Click
			' Gan tri man nhinh
			ISADDING = False
			ISEDITING = False

			ButtonStatus()
			txtCTTYP.Text = cboCTTYP.BoundText
			WriteToScreen()


		End Sub

		Private Sub cmdDelete_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDelete.Click
			Dim cmdExecute As Object
			Dim SQL As String
			SQL = "DELETE FROM RCT WHERE CTTYP = '" & cboCTTYP.BoundText & "'"

			cmdExecute = New ADODB.Command
			cmdExecute.ActiveConnection = DBconn
			cmdExecute.CommandText = SQL
			cmdExecute.Execute()
			Adodc1.Refresh()
			'WriteToScreen (0)

		End Sub

		Private Sub cmdEdit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEdit.Click
			ISEDITING = True
			' Ham gan tri man hinh
			ISADDING = False
			ISEDITING = True


			ButtonStatus()

		End Sub

		Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click
			Me.Close()

		End Sub

		Private Sub cmdSave_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSave.Click


			WriteToFile()
			Adodc1.Refresh()

			'''''''''''
			ISADDING = False
			ISEDITING = False

			ButtonStatus()


		End Sub

		Private Sub frmACR110_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
			'BIENCHUNG
			Adodc1.ConnectionString = ConnectString
			Adodc1.ConnectionTimeout = 10
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdTable
			Adodc1.RecordSource = "RCT"	'SALEMAN
			Adodc1.Refresh()

			ISADDING = False
			ISEDITING = False
			ButtonStatus()
			VB6_AddADODataBinding()
			cboCTTYP.RowSource = ADOBind_Adodc1.DataSource
		End Sub

		Private Sub txtCTTYP_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtCTTYP.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				If ValidMaso(OldCTTYP, txtCTTYP, "RCT", " CTTYP='" & txtCTTYP.Text & "'") Then
					MsgBox("This code is already exist")
					txtCTTYP.Focus()
				Else
					txtCTDSC.Focus()
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub
	End Class
End Namespace